﻿////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// <copyright>Copyright 2008-2011 Andreas Huber Doenni</copyright>
// Distributed under the Microsoft Public License (Ms-PL).
// See accompanying file License.txt or copy at http://mews.codeplex.com/license.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

namespace Mews.Net.Nntp
{
    using System;

    using Mews.Text;

    /// <summary>Represents a NEWNEWS command to be sent to an NNTP server, see
    /// <a href="http://www.ietf.org/rfc/rfc3977.txt">RFC 3977</a> 7.4.</summary>
    /// <remarks>Caution: Many NNTP servers do not allow this command.</remarks>
    /// <threadsafety static="true" instance="false"/>
    public sealed class NewNewsCommand : SingleLineCommand<NewNewsResponse>
    {
        private static readonly string[] successResponseCodes = { "230" };

        /// <summary>Initializes a new instance of the <see cref="NewNewsCommand"/> class.</summary>
        /// <exception cref="ArgumentNullException"><paramref name="wildmat"/> equals <c>null</c>.</exception>
        /// <exception cref="ArgumentException"><paramref name="wildmat"/> contains white space.</exception>
        public NewNewsCommand(string wildmat, DateTime dateTime) :
            base(StringHelper.Format("NEWNEWS {0} {1:yyyyMMdd HHmmss} GMT", wildmat, dateTime), 2, successResponseCodes)
        {
            CommandHelper.AssertContainsNoWhiteSpace("wildmat", wildmat);
        }

        /// <summary>See <see cref="SingleLineCommandBase{T, U}.CreateResponse"/>.</summary>
        protected sealed override NewNewsResponse CreateResponse(ResponseStream responseStream)
        {
            return new NewNewsResponse(responseStream);
        }
    }
}
